package com.lopo.sms;

import com.twilio.Twilio;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.rest.api.v2010.account.message.Feedback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.xml.soap.MessageFactory;
import java.net.URI;

@Component
@Slf4j
public class TwilioSms {
    public static final String ACCOUNT_SID = "AC517166e7e871eb7e9d37bcc835c032b9";
    public static final String AUTH_TOKEN = "dcc46150cfc0d41c89d0de36ac08a2fc";

    static {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
    }

    public void sendSms(String toPhone, String content) {
        Message message = Message.creator(
            new com.twilio.type.PhoneNumber(toPhone), // to
            "MG56712ab94fffb4c09f0b6ed5ce54653d", //from service池
            content)
            .setStatusCallback(URI.create("https://eoqrf1a66za1ijg.m.pipedream.net"))
            .create();
        log.info("{}", message);
    }

//    public static final String FROM_NUMBER = "+19794066520";

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Message message = Message.creator(
            new com.twilio.type.PhoneNumber("+16149166558"), // to
            "MG56712ab94fffb4c09f0b6ed5ce54653d", //from
            "老王")
            .setStatusCallback(URI.create("https://eoqrf1a66za1ijg.m.pipedream.net"))
            .create();
        System.out.println(message.toString());
    }
}
